//
//  NSNumber+KeepDigital.m
//  XiaoHongShu
//
//  Created by Jason on 2022/7/20.
//

#import "NSNumber+KeepDigital.h"

@implementation NSNumber (KeepDigital)

// 保留1位小数，并且不会四舍五入
+ (NSString *)keepOneDigitWithCount:(double)count {
    // 这是保留1位小数，并且不会四舍五入
    NSNumber *number = @(count);
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setPositiveFormat:@"###0.0"];
    formatter.maximumFractionDigits = 1;
    formatter.roundingMode = NSNumberFormatterRoundDown;
    NSLog(@"%@", [formatter stringFromNumber:number]);
    return [formatter stringFromNumber:number];
}

// 保留2位小数，并且不会四舍五入
+ (NSString *)keepTwoDigitalWithCount:(double)count {
    // 这是保留2位小数，并且不会四舍五入
    NSNumber *number = @(count);
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setPositiveFormat:@"###0.00"];
    formatter.maximumFractionDigits = 2;
    formatter.roundingMode = NSNumberFormatterRoundDown;
    NSLog(@"%@", [formatter stringFromNumber:number]);
    return [formatter stringFromNumber:number];
}


@end
